local zhuri = fk.CreateSkill {
  name = "lingling__zhuri",
}

Fk:loadTranslationTable{
  ["lingling__zhuri"] = "逐日",
  [":lingling__zhuri"] = "其他角色回合结束时，若其本回合未对你使用牌，你摸一张牌，否则你可以弃置X张牌，对其造成1点伤害"..
  "（X为其本回合对你使用的牌数）。",

  ["#lingling__zhuri-invoke"] = "逐日：你可以弃置%arg张牌，对 %dest 造成1点伤害",
}

zhuri:addEffect(fk.TurnEnd, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(zhuri.name) then
      local n = #player.room.logic:getEventsOfScope(GameEvent.UseCard, 999, function (e)
        local use = e.data
        return use.from == target and table.contains(use.tos, player)
      end, Player.HistoryTurn)
      event:setCostData(self, {n = n})
      if n == 0 then
        return true
      else
        return not target.dead and #player:getCardIds("he") >= n
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local n = event:getCostData(self).n
    if n == 0 then
      return true
    else
      local cards = room:askToDiscard(player, {
        min_num = n,
        max_num = n,
        include_equip = true,
        skill_name = zhuri.name,
        prompt = "#lingling__zhuri-invoke::"..target.id..":"..n,
        cancelable = true,
        skip = true,
      })
      if #cards == n then
        event:setCostData(self, {tos = {target}, cards = cards, n = n})
        return true
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local n = event:getCostData(self).n
    if n == 0 then
      player:drawCards(1, zhuri.name)
    else
      room:throwCard(event:getCostData(self).cards, zhuri.name, player, player)
      if not target.dead then
        room:damage{
          from = player,
          to = target,
          damage = 1,
          skillName = zhuri.name,
        }
      end
    end
  end,
})

return zhuri
